{include file="public/layout" /}
<body>
  <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body web-system" pad15>
                <div class="layui-form" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>链接类型</label>
                    <div class="layui-input-inline">
                       <input type="radio" name="typeid" lay-filter="typeid" value="1" title="文字" {if condition='$info.typeid == 1'}checked{/if}>
                       <input type="radio" name="typeid" lay-filter="typeid" value="2" title="图片" {if condition='$info.typeid == 2'}checked{/if}>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>网址URL</label>
                    <div class="layui-input-inline">
                     <input type="text" name="url" value="{$info.url|default=''}" lay-verify="required|url" placeholder="http://" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"><b>*</b>网站名称</label>
                    <div class="layui-input-inline">
                     <input type="text" name="title" value="{$info.title|default=''}" lay-verify="required" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item typeid2 {if condition='$info.typeid == 1'}none{/if}">
                    <label class="layui-form-label"><b>*</b>上传Logo</label>
                    <div class="layui-input-inline">
                        <div class="upload-box">
                          <div class="upload-img fl">
                            <div class="icaction none">
                              <span class="load_images">
                                 <a href="javascript:void(0);" onclick="BigImages($('#img_logo').attr('src'));">
                                 <i class="layui-icon layui-icon-search mr5"></i>查看
                                 </a>
                              </span>
                              <span class="load_images">
                                <a href="javascript:void(0);" data-inputid="logo" onclick="DelImages(this);">
                                <i class="layui-icon layui-icon-delete mr5"></i>删除
                                </a>
                              </span>
                            </div>
                            <div class="cover-bg none"></div>
                            <img id="img_logo" src="{$info.logo|get_default_pic=###}">
                          </div>
                          <div class="upload-right fl">
                            <button class="layui-btn test-upload-demoMore layui-btn-primary layui-btn-sm fl mb10 mr5" lay-data="{number:1,ey_inputId:'logo',ey_savepath:'allimg'}"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                            <button class="layui-btn layui-btn-sm layui-btn-primary layui-btn-sm fl mb10" onClick="GetPictureFolder(1,'logo');"><i class="layui-icon">&#xe64a;</i>图库</button>
                            <input name="logo" id="logo" placeholder="图片地址" value="{$info.logo|default=''}" class="layui-input">
                          </div>
                        </div>
                    </div>
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                      <div class="ey_helptips_txt">建议尺寸 88 * 31 (像素) 的gif或jpg文件</div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-inline">
                      <input type="text" name="sort_order" value="{$info.sort_order|default='100'}" lay-verify="number" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container " style="width: auto;">
                      <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                      <div class="layui-form-inline2 ey_helptips_txt">越小越靠前</div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">站长Email</label>
                    <div class="layui-input-inline">
                      <input type="text" name="email" value="{$info.email|default=''}" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">网站备注</label>
                    <div class="layui-input-inline">
                      <textarea name="intro" class="layui-textarea" placeholder="备注一些站长联系方式、信息等内容">{$info.intro|default=''}</textarea>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">新窗口打开</label>
                    <div class="layui-input-inline w70">
                        <input type="checkbox" lay-filter="target" lay-skin="switch" lay-text="是|否" {if condition="$info.target eq 1"}checked{/if}>
                        <input type="hidden" name="target" value="{$info.target|default='0'}" />
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="id" value="{$info.id}">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                    </div>
                  </div>
              </div>
            </div>
          </div>
        </div>
  </div>

  <script>

  $(document).ready(function(){
      // 鼠标事件，加载查看大图和删除图片
      $(".upload-img").live('mouseover', function(){
          $(this).find('div.icaction').show();
          $(this).find('div.cover-bg').show();
      }).live('mouseout', function(){
          $(this).find('div.icaction').hide();
          $(this).find('div.cover-bg').hide();
      });
  });

  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,form = layui.form;
      
    form.verify({
      check_logo: function(value, item){ //value：表单的值、item：表单的DOM对象
        if ($('input[name=typeid]:checked').val() == 2) {
            if(value == ''){
                return '请上传Logo图片！';
            }
        }
      }
    }); 

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    // 监听单选项
    form.on('radio(typeid)', function(data){
        if (data.value == 2) {
            $('.typeid2').show();
        } else {
            $('.typeid2').hide();
        }
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('Links/edit')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.gourl(res.url);
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });

  });

  </script>
{include file="public/footer" /}